#ifndef __CLIENT_FILE_SYNCFILE_included
#define __CLIENT_FILE_SYNCFILE_included

#include <string>
#include "../client-common/Record.h"
#include "../client-common/TableCached.h"

using namespace std;

enum {
	FILE_STATUS_NORMAL = 0,
	FILE_STATUS_DELETED = 1,
	FILE_STATUS_LOST = 2
};

enum {
	FILE_TYPE_FILE = 1,
	FILE_TYPE_FOLDER = 2
};

namespace Client {
namespace File {

using namespace Common;

class CSyncFile;
typedef boost::shared_ptr<CSyncFile> SyncFileRef;

class CSyncFile : public Common::CRecord {

public :

	string mId;	
	string mName;
	int mType;
	string mLastModifyDevice;
	int mVersion;
	string mOrigDevice;
	string mStorePath;
	string mOrigPath;
	string mStoreTag;
	Util::CSystem::Int64 mSize;
	string mParent;
	int mStatus;
	int mSyncCount;

	CSyncFile() : 
		mStatus(FILE_STATUS_NORMAL), mSyncCount(0), mType(FILE_TYPE_FILE), mVersion(0), mSize(0)
	{ }

	CSyncFile(JsonValue& v);
	CSyncFile(CDBCursor& c);
	CSyncFile(string& file_path, CSyncFile* parent);
	virtual string& GetTableName();
	virtual void GetValueSet(map<string, string>& values);
	virtual void WriteJson(JsonWriter& writer);

	static TableRef Query();
	static TableRef QueryAfter(int ver);
	static SyncFileRef QueryById(string& id);
	static void DelFile(CSyncFile& sf);
	static SyncFileRef AddLocalFile(string& file_path, CSyncFile* parent);
	static bool AddSyncFile(SyncFileRef sf);
	static bool UpdateSyncFile(SyncFileRef sf);
	static TableRef GetSerializedTable(string& js);
	static TableRef GetSerializedTable(CTable& table);
	static bool LessVersion(const SyncFileRef& sf1, const SyncFileRef& sf2);
	static void AddTrigger(TableTriggerRef trig);
};



} // Client
} // File

#endif //__CLIENT_FILE_SYNCFILE_included